import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { UserForm, UserInfo, UserPageVO, UserQuery, OptionType } from "./types";
let device = "riskrule";
/**
 * 登录成功后获取用户信息（昵称、头像、权限集合和角色集合）
 */
export function getUserInfoApi(): AxiosPromise<UserInfo> {
  return request({
    url: "/api/v1/users/me",
    method: "get",
  });
}
/**
 * 获取用户分页列表
 *
 * @param queryParams
 */
export function getList(
  queryParams: PageQuery
): AxiosPromise<PageResult<UserPageVO[]>> {
  return request({
    url: `/system/computer/list`,
    method: "get",
    params: queryParams,
    headers: {
      // Authorization: "Bearer 06701627-b801-4ad6-a99d-ed100eb2b708", // 设置认证令牌
      // 'Content-Type': 'application/json' // 设置内容类型为JSON
    },
  });
}
export function getAreaList(): AxiosPromise<
  SelectResult<
    {
      areaname: string;
      areaid: string;
    }[]
  >
> {
  return request({
    url: `/system/area/list`,
    method: "get",
  });
}
export function getVPNList(): AxiosPromise<SelectResult<string[]>> {
  return request({
    url: `/system/radiusLog/queryNasIpLists`,
    method: "get",
  });
}
//
/**
 * 获取用户分页列表
 *
 * @param queryParams
 */
export function getUserPage(
  queryParams: UserQuery
): AxiosPromise<PageResult<UserPageVO[]>> {
  return request({
    url: "/api/v1/users/page",
    method: "get",
    params: queryParams,
  });
}

/**
 * 获取用户表单详情
 *
 * @param userId
 */
export function getUserForm(userId: number): AxiosPromise<UserForm> {
  return request({
    url: "/api/v1/users/" + userId + "/form",
    method: "get",
  });
}

/**
 * 添加用户
 *
 * @param data
 */
export function addUser(data: any) {
  return request({
    url: "/api/v1/users",
    method: "post",
    data: data,
  });
}
export function addComputer(data: any) {
  return request({
    url: "/system/computer/add",
    method: "post",
    params: data,
  });
}

export function editComputer(data: any) {
  return request({
    url: "/system/computer/edit",
    method: "post",
    params: data,
  });
}
export function delComputer(data: any) {
  return request({
    url: "system/computer/updateStatus",
    method: "post",
    params: data,
  });
}
export const ComputerConfigList = (params: any) => {
  return request({
    url: `system/computer/edgeParamsConfig`,
    params: params,
    method: "post",
  });
};
export const addEdgeParamsConfig = (params: any) => {
  return request({
    url: `/system/computer/addEdgeParamsConfig`,
    data: params,
    method: "post",
  });
};

/**
 * 修改用户
 *
 * @param id
 * @param data
 */
export function updateUser(id: number, data: UserForm) {
  return request({
    url: "/api/v1/users/" + id,
    method: "put",
    data: data,
  });
}

/**
 * 修改用户密码
 *
 * @param id
 * @param password
 */
export function updateUserPassword(id: number, password: string) {
  return request({
    url: "/api/v1/users/" + id + "/password",
    method: "patch",
    params: { password: password },
  });
}

/**
 * 删除用户
 *
 * @param ids
 */
export function deleteUsers(ids: string) {
  return request({
    url: "/api/v1/users/" + ids,
    method: "delete",
  });
}

/**
 * 下载用户导入模板
 *
 * @returns
 */
export function downloadTemplateApi() {
  return request({
    url: "/api/v1/users/template",
    method: "get",
    responseType: "arraybuffer",
  });
}

/**
 * 导出用户
 *
 * @param queryParams
 * @returns
 */
export function exportUser(queryParams: UserQuery) {
  return request({
    url: "/api/v1/users/_export",
    method: "get",
    params: queryParams,
    responseType: "arraybuffer",
  });
}

/**
 * 导入用户
 *
 * @param file
 */
export function importUser(deptId: number, file: File) {
  const formData = new FormData();
  formData.append("file", file);
  return request({
    url: "/api/v1/users/_import",
    method: "post",
    params: { deptId: deptId },
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}
